package com.cq.hd.member.controller;

import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbMerchantEnterApplyApi;

import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.*;
import com.cq.hd.member.service.TbMerchantEnterApplyService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商户入驻申请记录表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-21
 */
@RestController
public class TbMerchantEnterApplyController implements TbMerchantEnterApplyApi {

    @Autowired
    private TbMerchantEnterApplyService merchantEnterApplyService;

    @ApiOperation(value = "商家审核商户个数")
    @ApiImplicitParam(name = "businessId", value = "商家id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = Integer.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Integer> getAuditCount(Long businessId) {
        return ResultGenerator.success(merchantEnterApplyService.getAuditCount(businessId));
    }

    @ApiOperation(value = "商户入驻审核列表")
    @ApiImplicitParam(name = "appMerchantEnterApplyPageDto", value = "实体", required = true, paramType = "query", dataType = "AppMerchantEnterApplyPageDto")
    @ApiResponse(response = AppMerchantEnterApplyPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<AppMerchantEnterApplyPageVo>> pageAppMerchantEnterApply(AppMerchantEnterApplyPageDto appMerchantEnterApplyPageDto) {
        return ResultGenerator.success(merchantEnterApplyService.pageAppMerchantEnterApply(appMerchantEnterApplyPageDto));
    }

    @ApiOperation(value = "管理后台：商户入驻审核列表")
    @ApiImplicitParam(name = "merchantEnterApplyPageDto", value = "实体", required = true, paramType = "query", dataType = "MerchantEnterApplyPageDto")
    @ApiResponse(response = AppMerchantEnterApplyPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<AdminMerchantEnterApplyPageVo>> pageAdminMerchantEnterApply(MerchantEnterApplyPageDto merchantEnterApplyPageDto) {
        return ResultGenerator.success(merchantEnterApplyService.pageAdminMerchantEnterApply(merchantEnterApplyPageDto));
    }

    @ApiOperation(value = "商户入驻详情")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = AppMerchantEnterApplyPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AppMerchantEnterApplyPageVo> details(Long id) {
        return ResultGenerator.success(merchantEnterApplyService.details(id));
    }

    @ApiOperation(value = "商户入驻审核")
    @ApiImplicitParam(name = "merchantEnterAuditDto", value = "实体", paramType = "body", dataType = "MerchantEnterAuditDto")
    @Override
    public Result<Boolean> audit(@RequestBody MerchantEnterAuditDto merchantEnterAuditDto) {
        return ResultGenerator.success(merchantEnterApplyService.audit(merchantEnterAuditDto));
    }

    @ApiOperation(value = "商户入驻申请")
    @ApiImplicitParam(name = "merchantEnterApplyDto", value = "实体", required = true, paramType = "body", dataType = "MerchantEnterApplyDto")
    @Override
    public Result<Boolean> apply(@RequestBody MerchantEnterApplyDto merchantEnterApplyDto) {
        return ResultGenerator.success(merchantEnterApplyService.apply(merchantEnterApplyDto));
    }

    @ApiOperation(value = "商户入驻预申请（供用户点击入驻申请链接调用）")
    @ApiImplicitParam(name = "preApplyMerchantDto", value = "实体", required = true, paramType = "body", dataType = "PreApplyMerchantDto")
    @Override
    public Result<PreApplyMerchantVo> preApply(@RequestBody PreApplyMerchantDto preApplyMerchantDto) {
        return ResultGenerator.success(merchantEnterApplyService.preApply(preApplyMerchantDto));
    }

    @ApiOperation(value = "商户入驻申请新的商家（已经入驻成功，登录后调用）")
    @ApiImplicitParam(name = "merchantEnterRepeatApplyDto", value = "实体", required = true, paramType = "body", dataType = "MerchantEnterRepeatApplyDto")
    @Override
    public Result<Boolean> repeatApply(@RequestBody MerchantEnterRepeatApplyDto merchantEnterRepeatApplyDto) {
        return ResultGenerator.success(merchantEnterApplyService.repeatApply(merchantEnterRepeatApplyDto));
    }

    @ApiOperation(value = "根据hfApplyNo+hfMerchantNo查询商户入驻列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hfApplyNo", value = "汇付申请单号", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "hfMerchantNo", value = "汇付商户号", required = true, paramType = "query", dataType = "String")
    })
    @Override
    public Result<List<MerchantEnterApplyPageVo>> listByApplyNoAndHfId(String hfApplyNo, String hfMerchantNo) {
        return ResultGenerator.success(merchantEnterApplyService.listByApplyNoAndHfId(hfApplyNo, hfMerchantNo));
    }

    @ApiOperation(value = "更新商户入驻信息")
    @ApiImplicitParam(name = "merchantEnterApplyUpdateDto", value = "实体", required = true, paramType = "body", dataType = "MerchantEnterApplyUpdateDto")
    @Override
    public Result<Boolean> updateMerchantEnterApplyById(@RequestBody MerchantEnterApplyUpdateDto merchantEnterApplyUpdateDto) {
        return ResultGenerator.success(merchantEnterApplyService.updateMerchantEnterApplyById(merchantEnterApplyUpdateDto));
    }

    @ApiOperation(value = "商户入驻成功处理商户账号和绑定处理")
    @Override
    public Result<Boolean> enterSuccess(Long id) {
        return ResultGenerator.success(merchantEnterApplyService.enterSuccess(id));
    }

    @ApiOperation(value = "根据openid获取商户入驻数据")
    @ApiImplicitParam(name = "openid", value = "openid", required = true, paramType = "query", dataType = "String")
    @ApiResponse(response = MerchantEnterApplyVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<MerchantEnterApplyVo> getEnterInfoByOpenid(String openid) {
        return ResultGenerator.success(merchantEnterApplyService.getEnterInfoByOpenid(openid));
    }

    @Override
    public Result<MerchantEnterApplyVo> getSuccessEnterInfoByOpenid(String openid) {
        return ResultGenerator.success(merchantEnterApplyService.getSuccessEnterInfoByOpenid(openid));
    }
}
